<?php
/**
 * Created by PhpStorm.
 * User: zd
 * Date: 2018/11/28
 * Time: 17:00
 */

namespace app\enterprise\service;


class Radar
{
    public $url = '';
    function __construct()
    {
        $this->url = config('setting.base_url');
    }
    /**
     * 请求行为数据
     * @param $page
     * @param $token
     * @param $timeInfo
     * @return null
     */
    public function getBehaviorList($page,$token){
        $url = $this->url."/behavior/list/";
        $params=['page'=>$page];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
       if ($data->code = 200){
            return $data->content;
       }else{
           return null;
       }
    }
    /**
     * 请求单个行为数据
     * @param $page
     * @param $token
     * @param $timeInfo
     * @return null
     */
    public function getBehaviorListByUser($uid,$page,$token){
        $url = $this->url."/behavior/user";
        $params=['uid'=>$uid,'page'=>$page];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }
    /**
     * 请求各行为的数据统计
     * @param $type
     * @param $token
     * @param $timeInfo
     * @return null
     */
    public function getBehaviorCount($type,$token,$timeInfo){
        $url = $this->url."/behavior/count";
        $params=['type'=>$type,"timeInfo"=>$timeInfo];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 根据分类查询个行为的统计
     * @param $type
     * @param $token
     * @param $timeInfo
     * @return null
     */
    public function getBehaviorByCategory($type,$token,$timeInfo,$page){
        $url = $this->url."/behavior/category";
        $params=['type'=>$type,"timeInfo"=>$timeInfo,'page'=>$page];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取用户列表
     * @param $token
     * @return null
     */
    public function getCustoms($timeInfo,$page,$size,$token){
        $url = $this->url."/behavior/custom";
        $params = ["timeInfo"=>$timeInfo,'page'=>$page,'size'=>$size];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取用户列表
     * @param $token
     * @return null
     */
    public function getCustomsById($user_id,$timeInfo,$token){
        $url = $this->url."/custom/behavior/".$user_id;
        $params = ['user_id'=>$user_id,"timeInfo"=>$timeInfo];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取排名
     * @param $timeInfo
     * @param $page
     * @param $size
     * @param $token
     * @return |null
     */
    public function getRanke($timeInfo,$page,$size,$token){
        $url = $this->url."/statistics/rank";
        $params = ['time'=>$timeInfo,'page'=>$page,'size'=>$size];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

/**
* 获取排名
* @param $timeInfo
* @param $page
* @param $size
* @param $token
* @return |null
*/
    public function getMyRanke($timeInfo,$token){
        $url = $this->url."/statistics/my";
        $params = ['time'=>$timeInfo];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 点赞
     * @param $id
     * @param $token
     * @return |null
     */
    public function createThumbsup($id,$token){
        $url = $this->url."/statistics/thumbsup";
        $params = ['id'=>$id];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 点赞列表
     * @param $id
     * @param $token
     * @return |null
     */
    public function getThumbsupList($id,$size,$page,$token){
        $url = $this->url."/statistics/thumbsup/list";
        $params = ['id'=>$id,'size'=>$size,'page'=>$page];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }






}